module ActiveScaffold
  module Helpers
    module ListColumns
      def active_scaffold_column_percentage(column, record)
        number_to_percentage(record[column.name].to_s, :precision => 1)
      end

      def active_scaffold_column_ssn(column, record)
        usa_number_to_ssn(record[column.name].to_s)
      end

      def active_scaffold_column_usa_money(column, record)
        number_to_currency(record[column.name].to_s)
      end

      def active_scaffold_column_usa_phone(column, record)
        usa_number_to_phone(record[column.name].to_s)
      end

      def active_scaffold_column_usa_zip(column, record)
        usa_number_to_zip(record[column.name].to_s)
      end

      # Allow in_place_editor to pass along nested information so the update_column can call refresh_record properly.
      def active_scaffold_inplace_edit(record, column)
        formatted_column = format_inplace_edit_column(record,column)
        id_options = {:id => record.id.to_s, :action => 'update_column', :name => column.name.to_s}
        tag_options = {:tag => "span", :id => element_cell_id(id_options), :class => "in_place_editor_field"}
        in_place_editor_options = {:url => {:controller => params_for[:controller], :action => "update_column", :eid => params[:eid], :parent_model => params[:parent_model], :column => column.name, :id => record.id.to_s},
         :click_to_edit_text => as_("Click to edit"),
         :cancel_text => as_("Cancel"),
         :loading_text => as_("Loading…"),
         :save_text => as_("Update"),
         :saving_text => as_("Saving…"),
         :script => true}.merge(column.options)
        # in_place_editor_options[:url].gsub!("&amp;", "&")
        content_tag(:span, formatted_column, tag_options) + in_place_editor(tag_options[:id], in_place_editor_options)
      end

    end
  end
end